#include <iostream>
using std::cout;
using std::endl;
//探究：派生类和基类构造函数的调用顺序
class Point{
public:
    Point(int x, int y)
    :_x(x)
    ,_y(y)
    {
        cout << "Point()" << endl;
    }
private:
    int _x;
    int _y;
};

class Point3D : public Point{
public:
    Point3D(int x, int y, int z)
    :Point(x, y)
    ,_z(z)
    {
        cout << "Point3D" << endl;
    }

private:
    int _z;
};
void test(){
    Point3D pt3d(1, 2, 3);

    cout << sizeof(Point) << endl; //8
    cout << sizeof(Point3D) << endl; //12
    //验证此时的内存布局是什么样的？？？
    //猜想12个字节是_x _y _z组成的，希望通过代码验证猜想
    Point3D * p = &pt3d;
    //强转为int*
    //打印的结果分别是1 2 3 证实猜想
    int * pInt = (int *)p;
    cout << *pInt << endl;
    cout << *(pInt + 1) << endl;
    cout << *(pInt + 2) << endl;
}

int main()
{
    test();
    return 0;
}

